package com.example.aopdemo.proxy;

import net.sf.cglib.proxy.Enhancer;

import java.lang.reflect.Proxy;

public class Main {

    public static void main(String[] args) {
        HouseSubject target = new RealHouseSubject();

        /**
         * JDK 的方式
         */
//        HouseSubject proxy = (HouseSubject) Proxy.newProxyInstance(
//                target.getClass().getClassLoader(),
//                new Class[]{HouseSubject.class},
//                new JDKInvocatonHandler(target)
//        );
//        proxy.rentHouse();
//        proxy.saleHouse();
        /**
         * CGLib 的方式
         */
//        HouseSubject proxy = (HouseSubject) Enhancer.create(target.getClass(),new CGLIBInterceptor(target));
//        proxy.saleHouse();
        HouseSubject proxy3 = (HouseSubject) Enhancer.create(target.getClass(), new CGLibIntercepter(target));
        proxy3.rentHouse();


    }
}
